package com.interview.ujiuye4;

import java.util.concurrent.*;

class MyThread implements Callable<Integer>{
    @Override
    public Integer call() throws Exception {
        System.out.println("执行业务方法.......");
        try { TimeUnit.SECONDS.sleep(3); } catch (InterruptedException e) { e.printStackTrace(); }
        return 1024;
    }
}



public class CallableTest {

    public static void main(String[] args) throws ExecutionException, InterruptedException, TimeoutException {
        MyThread myThread = new MyThread();
        FutureTask<Integer> futureTask = new FutureTask<>(myThread);
        Thread thread = new Thread( futureTask );
        thread.start();
        //Integer integer = futureTask.get(1,TimeUnit.SECONDS);
        //System.out.println(integer);
        Integer integer = null;
        while( !futureTask.isDone() ){
        }
        integer = futureTask.get();
        System.out.println(integer);


    }
}
